package com.juicygames.undoer.fps;

public class FpsCounter {
	
	private int framesCount = 0;
	private float framesPerSecond = 0f;
	private final long halfMinuteInNano = 500000000l;
	private long lastTimeInHalfMinutes;
	
	public FpsCounter(long startTime) {
		lastTimeInHalfMinutes = startTime / halfMinuteInNano;
	}
	
	public void count(long currentTime) {
		
		long nowTimeInHalfMinutes = currentTime / halfMinuteInNano;
		framesCount = framesCount + 1;
		
		if (nowTimeInHalfMinutes > lastTimeInHalfMinutes) {
			
			framesPerSecond = framesCount * 2;
			lastTimeInHalfMinutes = nowTimeInHalfMinutes;
			framesCount = 0;
		}
	}
	
	public float getFps() {
		return framesPerSecond;
	}

}
